<?php
Namespace Cyfy\Modules\Errors;

use \Cyfy\Modules\BasicContent\Content;

/**
 * Module handling various errors - eq. 404
 *
 * @author dandelion
 * @version 0.1
 */
class Module extends \Cyfy\Module
{
    /**
     * Administration UI
     */
    static function administration($name = "")
	{	
    
        switch($name)
        {
            case "404":
                return self :: edit404();
                break;
                
            case "":
                return array(
                    "404" => array("name" => self :: t(10), "description" => self :: t(20), "permission" => "administration")
                );
            default:
                return false;
		}	
	
	}
	
    /**
     * Returns the error text.
     *
     * @param string Name - mostly error code.
     */
	static function get($name)
	{
		switch($name)
        {
            case "404":
                return self :: show404();
        }
	}
	
    /**
     * Returns text of error 404.
     * @return string HTML content
     */
    static private function show404()
    {
        $c = Content :: load(self :: constant("404"));
        if(!$c){
            return "404 error not found, check settings.";
        }
                       
        \Cyfy\Template :: setTitle($c -> getTitle());
        
        $output = "<h2>" . $c -> getTitle() . "</h2>";
        $output .= strtr($c -> getContent(), array("#PAGE#" => $_SESSION["404url"]));
        
        return $output;
    }
    
    /**
     * Edits error text.
     * @return string HTML content - form
     */
    static private function edit404()
    {
        $form = new Forms\Edit404();
        
        // values?
        $c = Content :: load(self :: constant("404"));
        if($c){
            $form -> setData(array(
                "title" => $c -> getTitle(),
                "content" => $c -> getContent()
            ));
        }
        return $form -> show();
    }
    
    
}